﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Grid;

namespace Cinser.Common.Wpf.Controls
{
    /// <summary>
    /// QueryListWindowBase查询列表窗体基类
    /// </summary>
    public partial class QueryListWindowBase : UserControl
    {
        public Grid MainGrid
        {
            get { return _MainGrid; }
            set { _MainGrid = value; }
        }

        public Grid QueryWindow
        {
            get { return _QueryWindow; }
            set { _QueryWindow = value; }
        }

        public cButton BtnQuery
        {
            get { return _BtnQuery; }
            set { _BtnQuery = value; }
        }

        public GridControl ListGrid
        {
            get { return _ListGrid; }
            set { _ListGrid = value; }
        }

        public Pager Pager
        {
            get { return _Pager; }
            set { _Pager = value; }
        }

        public QueryListWindowBase()
        {
            InitializeComponent();
        }

        public void AddQueryConditionField(List<QueryConditionField> conditions)
        {
            double labelWidth = 100;
            int columnsCount = conditions.Count + 1;
            if(columnsCount<3)
                columnsCount = 4;
            double totalWidth = this.ActualWidth;

            for (int i = 0; i < columnsCount / 2; i++)
            {
                this.QueryWindow.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(labelWidth) });
                this.QueryWindow.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(175) });
            }

            for (int i = 0; i < conditions.Count; i++)
            {
                int lbColumnIndex = 2 * i;
                int lbRowIndex = 0;
                if (lbColumnIndex + 2 >= columnsCount)
                    lbRowIndex = 1;

                Label label = new Label();
                label.Content = conditions[i].Name;
                Grid.SetRow(label, lbRowIndex);
                Grid.SetRow(label, lbColumnIndex);
                this.QueryWindow.Children.Add(label);

                Grid.SetRow(conditions[i].Control, lbRowIndex);
                Grid.SetRow(conditions[i].Control, lbColumnIndex + 1);
                this.QueryWindow.Children.Add(conditions[i].Control);
            }

            Grid.SetColumn(this.BtnQuery, columnsCount - 1);
        }

        public class QueryConditionField
        {
            public string Name { set; get; }
            public Control Control { set; get; }
        }
    }
}
